import processing.core.PApplet;

public class radial {
	boolean hover = false;
	boolean pressing = false;
	boolean showValues = false;
	boolean selected = false;
	boolean resizeSel = false;
	boolean rename = false;

	// position in graphs array
	int i;

	// default dimensions
	// box dimensions:
	int x = 200;
	int y = 200;
	int w = 100;
	int h = 100;

	// select box dimensions:
	int degree = 0;


	PApplet parent;

	public radial(PApplet p) {
		parent = p;
		new RRect(parent);
	}
	
	public radial() {
		
	}

	int[] radialColor = { 210, 210, 210, 255 };
	int _color = 255;
	int _colorSel = 230;
	String label = "default";

	void init(int x, int y, int w, int h, String label, boolean showValues,
			int i) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.label = label;
		this.showValues = showValues;
		this.degree = 0;
		this.i = i;
		display();
	}

	void init(int x, int y, int w, int h, String label, boolean showValues,
			int i, int startPos) {
		this.x = x;
		this.y = y;
		this.w = w;
		this.h = h;
		this.i = i;
		this.label = label;
		this.showValues = showValues;
		this.degree = startPos;
		display();
	}

	void display() {

		
		if (Main.editMode && selected) {
			parent.fill(110, 110, 110, 255);
			parent.ellipse(x, y, w, h);
			parent.fill(0);
			parent.line(x,y,(float)(x-PApplet.sin((float) (degree*PApplet.PI/180.))*w/2.),
					(float) (y+PApplet.cos((float) (degree*PApplet.PI/180.))*h/2.));
			parent.text(label, x-h/2,y+h/2+20);
		} else {
			if (hover) {
				parent.fill(230, 230, 230, 255);
				parent.ellipse(x, y, w, h);
				parent.fill(0);
				parent.line(x,y,(float)(x-PApplet.sin((float) (degree*PApplet.PI/180.))*w/2.),
						(float) (y+PApplet.cos((float) (degree*PApplet.PI/180.))*h/2.));
				parent.text(label, x-h/2,y+h/2+20);
			} else {
				parent.fill(radialColor[0], radialColor[1], radialColor[2], radialColor[3]);
				parent.ellipse(x, y, w, h);
				parent.fill(0);
				parent.line(x,y,(float)(x-PApplet.sin((float) (degree*PApplet.PI/180.))*w/2.),
						(float) (y+PApplet.cos((float) (degree*PApplet.PI/180.))*h/2.));
				parent.text(label, x-h/2,y+h/2+20);
			}

			if (pressing) {
				degree = (2*(parent.pmouseY - parent.mouseY) + degree);
				if (degree>359) {
					degree = 359;
				}
				if (degree<0) {
					degree=0;
				}
				UIActions.radialAction(i);

				parent.fill(230, 230, 230, 255);
				parent.ellipse(x, y, w, h);
				parent.fill(0);
				parent.line(x,y,(float)(x-PApplet.sin((float) (degree*PApplet.PI/180.))*w/2.),(float) (y+PApplet.cos((float) (degree*PApplet.PI/180.))*h/2.));
				parent.text(label, x-h/2,y+h/2+20);
			}
		}
		if (showValues) {
			parent.fill(0);
			parent.text(String.format("%.2f",(degree/360.)), x-h/2, y+h/2 +40);

		}
	}
	Object[] toObj() {
		Object[] object = new Object[17];
		object[0]=i;
		object[1]=x;
		object[2]=y;
		object[3]=w;
		object[4]=h;
		object[5]=degree;
		object[6]=radialColor[0];
		object[7]=radialColor[1];
		object[8]=radialColor[2];
		object[9]=radialColor[3];
		object[10]=_color;
		object[11]=_colorSel;
		object[12]=label;
		object[13]=showValues;
		return object;
	}
}
